package br.com.appestoque.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Tempo {
	
	public static Date primeiroDiaMes(Date data) {
		Calendar calendar = GregorianCalendar.getInstance();
		calendar.setTime(data);
		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}
	
	public static Date ultimoDiaMes(Date data) {
		Calendar calendar = GregorianCalendar.getInstance();
		calendar.setTime(data);
		calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		return calendar.getTime();
	}
	
	public static Date stringParaData(String data) {
		SimpleDateFormat sdf = new SimpleDateFormat(Constantes.FORMATO_DATA_PADRAO);
		Date dt = null;
		try {
			dt = sdf.parse(data);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return dt;
	}

}